(function(){if(window.BXMainMailConfirm)return;var e={};var t=[];var a={};var i;var n={init:function(a){t=a.mailboxes;i=a.action;delete a.mailboxes;e=a},getMailboxes:function(){return t},showList:function(e,i,o){if(!BX.type.isNotEmptyString(o.placeholder)){o.placeholder=BX.message(o.required?"MAIN_MAIL_CONFIRM_MENU_UNKNOWN":"MAIN_MAIL_CONFIRM_MENU_PLACEHOLDER")}if(!(o.settings&&o.settings.length)){o.settings=[]}if(!BX.type.isFunction(o.callback)){o.callback=function(){}}if(typeof o.popupSettings!="object"){o.popupSettings={}}o.popupSettings.className="main-mail-confirm-menu-content";o.popupSettings.offsetLeft=40;o.popupSettings.angle=true;o.popupSettings.closeByEsc=true;a[e]=o;var l=[];var s=function(i,o){var l="apply";if(i&&i.target){var s="main-mail-confirm-menu-delete-icon";if(BX.hasClass(i.target,s)||BX.findParent(i.target,{class:s},o.layout.item)){l="delete"}if(BX.hasClass(i.target,"sender-hint")||BX.findParent(i.target,{class:"sender-hint"},o.layout.item)){l="edit"}}if("delete"==l){n.deleteSender(o.id,(function(){t=t.filter((function(e,t){return o.id!==e.id}));o.menuWindow.removeMenuItem(o.id);if(a[e].selected==o.title){a[e].callback("",a[e].placeholder)}}))}else if("edit"===l){n.showEditForm(o.id)}else{a[e].callback(o.title,o.text);o.menuWindow.close()}};if(!o.required){l.push({text:BX.util.htmlspecialchars(o.placeholder),title:"",onclick:s});l.push({delimiter:true})}if(t&&t.length>0){var r,d;for(var m in t){d="menu-popup-no-icon";r=BX.util.htmlspecialchars(t[m].formated);if(t[m]["can_delete"]&&t[m].id>0){r+='<span class="main-mail-confirm-menu-delete-icon popup-window-close-icon popup-window-titlebar-close-icon"\t\t\t\t\t\t\t\ttitle="'+BX.util.htmlspecialchars(BX.message("MAIN_MAIL_CONFIRM_DELETE"))+'"></span>';d="menu-popup-no-icon menu-popup-right-icon";r+='<span data-role="sender-hint"  class="sender-hint main-mail-edit-icon"\t\t\t\t\t\t\t\ttitle="'+BX.util.htmlspecialchars(BX.message("MAIN_MAIL_CONFIRM_EDIT"))+'"></span>';d="menu-popup-no-icon menu-popup-right-icon"}l.push({html:r,title:t[m].formated,mailbox:t[m],onclick:s,className:d,id:t[m].id})}l.push({delimiter:true})}l.push({text:BX.util.htmlspecialchars(BX.message("MAIN_MAIL_CONFIRM_MENU")),onclick:function(i,o){o.menuWindow.close();n.showForm((function(i,n){t.push({email:i.email,name:i.name,id:i.id,formated:n,can_delete:true});a[e].callback(n,BX.util.htmlspecialchars(n));BX.PopupMenu.destroy(e+"-menu")}))}});if(o.settings.length>0){l=l.concat(o.settings)}BX.PopupMenu.show(e+"-menu",i,l,o.popupSettings)},showForm:function(e,t){window.step="email";var a;window.mode=t&&t.mode?t.mode:"add";var i=new BX.PopupWindow("add_from_email",null,{titleBar:BX.message("MAIN_MAIL_CONFIRM_TITLE"),draggable:true,closeIcon:true,lightShadow:true,contentColor:"white",contentNoPaddings:true,cacheable:false,content:BX("new_from_email_dialog_content").innerHTML,buttons:this.prepareDialogButtons(null,"add",t,e)});this.prepareDialog(i)},prepareDialog:function(t){t.formFieldHint=function(e,t,a){if(!e){return}var i=BX.findParent(e,{class:"new-from-email-dialog-cell"});var n=BX.findChildByClassName(i,"new-from-email-dialog-field-hint",true);BX.removeClass(i,"new-from-email-dialog-field-error");BX.removeClass(i,"new-from-email-dialog-field-warning");switch(t){case"error":BX.addClass(i,"new-from-email-dialog-field-error");break;case"warning":BX.addClass(i,"new-from-email-dialog-field-warning");break}if(typeof a!="undefined"&&a.length>0){BX.adjust(n,{html:a});BX.show(n,"block")}else{BX.hide(n,"block")}};t.hideNotify=function(){var e=BX.findChild(t.contentContainer,{class:"new-from-email-dialog-error"},true);if(e){BX.hide(e,"block")}};t.showNotify=function(e){var a=BX.findChild(t.contentContainer,{class:"new-from-email-dialog-error"},true);if(a){a.innerHTML=e;BX.show(a,"block")}};t.switchBlock=function(a,i){var n=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-email-block",true);var o=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-code-block",true);var l,s;if("code"!=step&&"code"==a){l=n;s=o;t.buttons[0].setName(BX.message("MAIN_MAIL_CONFIRM_SAVE"));t.buttons[1].setName(BX.message("MAIN_MAIL_CONFIRM_BACK"))}else if("code"==step&&"code"!=a){l=o;s=n;t.buttons[0].setName(BX.message("smtp"==a&&e.canCheckSmtp?"MAIN_MAIL_CONFIRM_SAVE":"MAIN_MAIL_CONFIRM_GET_CODE"));t.buttons[1].setName(BX.message("MAIN_MAIL_CONFIRM_CANCEL"))}step=a;if(l&&s){if(i){s.style.position="";s.style.height="";s.style.display="";l.style.display="none"}else{l.style.height=l.offsetHeight+"px";l.offsetHeight;l.style.height="0px";s.style.position="absolute";s.style.height="";s.style.display="";var r=s.offsetHeight;s.style.height="0px";s.style.position="";s.offsetHeight;s.style.height=r+"px"}}};var a=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-smtp-link",true);var i=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-smtp-block",true);var n=BX.findChildByClassName(t.contentContainer,"new-from-email-smtp-use-limit",true);if(n){BX.bind(n,"click",(function(){var e=BX.findChildByClassName(t.contentContainer,"new-from-email-smtp-use-limit",true);var a=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-email-block",true);var i=BX.findChild(a,{attr:{"data-name":"smtp-limit"}},true);i.disabled=!e.checked}))}if(a&&i){BX.bind(a,"click",(function(a){var n=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-email-block",true);n.style.height="";if("smtp"==step){step="email";BX.hide(i,"table-row-group");t.buttons[0].setName(BX.message("MAIN_MAIL_CONFIRM_GET_CODE"))}else{step="smtp";BX.show(i,"table-row-group");t.buttons[0].setName(BX.message(e.canCheckSmtp?"MAIN_MAIL_CONFIRM_SAVE":"MAIN_MAIL_CONFIRM_GET_CODE"))}a.preventDefault()}))}if("confirm"==window.mode){t.switchBlock("code",true);t.setOverlay(true)}t.show();var o=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-email-block",true);var l=BX.findChild(o,{attr:{"data-name":"name"}},true);var s=BX.findChild(o,{attr:{"data-name":"email"}},true);if(l.value.length>0){s.focus()}else{l.focus()}},showEditForm:function(e){window.step="email";window.mode="edit";var t=new BX.PopupWindow("edit_from_email",null,{titleBar:BX.message("MAIN_MAIL_CONFIRM_EDIT_TITLE"),draggable:true,closeIcon:true,lightShadow:true,contentColor:"white",contentNoPaddings:true,cacheable:false,content:BX("new_from_email_dialog_content").innerHTML,events:{onPopupShow:function(){BX.ajax({url:BX.util.add_url_param(i,{act:"info",senderId:e}),method:"GET",dataType:"json",onsuccess:function(e){var a=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-email-block",true);var i=BX.findChildByClassName(t.contentContainer,"new-from-email-dialog-smtp-link",true);var n=BX.findChildByClassName(t.contentContainer,"new-from-email-smtp-use-limit",true);var o=BX.findChild(a,{attr:{"data-name":"name"}},true);var l=BX.findChild(a,{attr:{"data-name":"email"}},true);var s=BX.findChild(a,{attr:{"data-name":"smtp-server"}},true);var r=BX.findChild(a,{attr:{"data-name":"smtp-port"}},true);var d=BX.findChild(a,{attr:{"data-name":"smtp-ssl"}},true);var m=BX.findChild(a,{attr:{"data-name":"smtp-login"}},true);var u=BX.findChild(a,{attr:{"data-name":"smtp-limit"}},true);o.value=e.name||"";l.value=BX.util.htmlspecialchars(e.email);s.value=BX.util.htmlspecialchars(e.server||"");r.value=BX.util.htmlspecialchars(e.port||"");m.value=BX.util.htmlspecialchars(e.login||"");var c=typeof e.limit==="undefined"||e.limit===null;u.value=c?u.value:e.limit;if(!c){n.checked=true;u.disabled=false}if(e.protocol==="smtps"){d.checked=true}if(e.server){BX.fireEvent(i,"click")}},onfailure:function(e){}})}},buttons:this.prepareDialogButtons(e,"edit")});this.prepareDialog(t)},prepareDialogButtons:function(e,t,a,n){return[new BX.PopupWindowButton({text:BX.message("MAIN_MAIL_CONFIRM_GET_CODE"),className:"popup-window-button-create",events:{click:function(o,l){var s=this;var r=s.popupWindow;if(BX.hasClass(s.buttonNode,"popup-window-button-wait"))return;var d=BX.findChildByClassName(r.contentContainer,"new-from-email-dialog-email-block",true);var m=BX.findChildByClassName(r.contentContainer,"new-from-email-dialog-code-block",true);var u=BX.findChild(d,{attr:{"data-name":"name"}},true);var c=BX.findChild(d,{attr:{"data-name":"email"}},true);var f=BX.findChild(m,{attr:{"data-name":"code"}},true);var p=BX.findChild(r.contentContainer,{attr:{"data-name":"public"}},true);var h=BX.findChild(d,{attr:{"data-name":"smtp-server"}},true);var _=BX.findChild(d,{attr:{"data-name":"smtp-port"}},true);var B=BX.findChild(d,{attr:{"data-name":"smtp-ssl"}},true);var C=BX.findChild(d,{attr:{"data-name":"smtp-login"}},true);var N=BX.findChild(d,{attr:{"data-name":"smtp-password"}},true);var M=BX.findChild(d,{attr:{"data-name":"smtp-limit"}},true);r.formFieldHint(N);if("email"==window.step||"smtp"==window.step){f.value="";var w="[=a-z0-9_+~'!$&*^`|#%/?{}-]";var I=new RegExp("^"+w+"+(\\."+w+"+)*@([a-z0-9-]+\\.)+[a-z0-9-]{2,20}$","i");if(!c.value.match(I)){r.showNotify(BX.message(c.value.length>0?"MAIN_MAIL_CONFIRM_INVALID_EMAIL":"MAIN_MAIL_CONFIRM_EMPTY_EMAIL"));return}}if("smtp"==window.step){if(!h.value.match(/^([a-z0-9-]+\.)+[a-z0-9-]{2,20}$/)){r.showNotify(BX.message(h.value.length>0?"MAIN_MAIL_CONFIRM_INVALID_SMTP_SERVER":"MAIN_MAIL_CONFIRM_EMPTY_SMTP_SERVER"));return}if(!_.value.match(/^[0-9]+$/)||_.value<1||_.value>65535){r.showNotify(BX.message(_.value.length>0?"MAIN_MAIL_CONFIRM_INVALID_SMTP_PORT":"MAIN_MAIL_CONFIRM_EMPTY_SMTP_PORT"));return}if(!(C.value.length>0)){r.showNotify(BX.message("MAIN_MAIL_CONFIRM_EMPTY_SMTP_LOGIN"));return}if(!e&&N.value.length>0){if(N.value.match(/^\^/)){r.showNotify(BX.message("MAIN_MAIL_CONFIRM_INVALID_SMTP_PASSWORD_CARET"));return}else if(N.value.match(/\x00/)){r.showNotify(BX.message("MAIN_MAIL_CONFIRM_INVALID_SMTP_PASSWORD_NULL"));return}else if(N.value.match(/^\s|\s$/)){r.formFieldHint(N,"warning",BX.message("MAIN_MAIL_CONFIRM_SPACE_SMTP_PASSWORD"))}}else if(!e){r.showNotify(BX.message("MAIN_MAIL_CONFIRM_EMPTY_SMTP_PASSWORD"));return}}if("code"==window.step){if(f.value.length==0){r.showNotify(BX.message("MAIN_MAIL_CONFIRM_EMPTY_CODE"));return}}r.hideNotify();BX.addClass(s.buttonNode,"popup-window-button-wait");var X={id:e,name:u.value,email:c.value,smtp:{},code:"",public:p.checked?p.value:""};if("smtp"==window.step){X.smtp={server:h.value,port:_.value,ssl:B.checked?B.value:"",login:C.value,password:N.value,limit:M.disabled?null:M.value}}if("code"==window.step){X.code=f.value}if(a&&a.data){for(var g in a.data){if(a.data.hasOwnProperty(g)){X[g]=a.data[g]}}}BX.ajax({url:BX.util.add_url_param(i,{act:t}),method:"POST",dataType:"json",data:X,onsuccess:function(t){BX.removeClass(s.buttonNode,"popup-window-button-wait");if(t.senderId){e=t.senderId}if(t.result=="error"){r.showNotify(t.error)}else if(("email"==window.step||"smtp"==window.step)&&!t.confirmed){r.formFieldHint(N);r.switchBlock("code")}else{s.popupWindow.close();if(n&&BX.type.isFunction(n)){var a=u.value.length>0?u.value:BX.message("MAIN_MAIL_CONFIRM_USER_FULL_NAME");n({name:a,email:c.value,id:e},a.length>0?a+" <"+c.value+">":c.value)}}},onfailure:function(){BX.removeClass(s.buttonNode,"popup-window-button-wait");r.showNotify(BX.message("MAIN_MAIL_CONFIRM_AJAX_ERROR"))}})}}}),new BX.PopupWindowButton({text:BX.message("MAIN_MAIL_CONFIRM_CANCEL"),className:"popup-window-button-link",events:{click:function(){var e=this.popupWindow;if("code"==window.step&&"confirm"!=window.mode){var t=BX.findChildByClassName(e.contentContainer,"new-from-email-dialog-smtp-block",true);e.switchBlock(t&&t.offsetHeight>0?"smtp":"email")}else{this.popupWindow.close()}}}})]},updateListCanDel:function(e){BX.ajax({url:BX.util.add_url_param(i,{act:"sendersListCanDel"}),method:"POST",dataType:"json",data:{},onsuccess:function(a){if(a.result=="error"){BX.UI.Notification.Center.notify({content:BX.message("MAIN_MAIL_DELETE_SENDER_ERROR")})}else{t=t.filter((function(e,t){if(!e.can_delete){return true}for(var i in a.mailboxes){if(a.mailboxes[i].id==e.id){return true}}return false}));BX.PopupMenu.destroy(e+"-menu")}},onfailure:function(e){BX.UI.Notification.Center.notify({content:BX.message("MAIN_MAIL_DELETE_SENDER_ERROR")})}})},deleteSender:function(e,t){BX.UI.Dialogs.MessageBox.show({message:BX.message("MAIN_MAIL_CONFIRM_DELETE_SENDER_CONFIRM"),modal:true,buttons:BX.UI.Dialogs.MessageBoxButtons.OK_CANCEL,onOk:function(a){return new Promise((function(a,n){BX.ajax({url:BX.util.add_url_param(i,{act:"delete"}),method:"POST",dataType:"json",data:{senderId:e},onsuccess:function(e){if(e.result=="error"){BX.UI.Notification.Center.notify({content:BX.message("MAIN_MAIL_DELETE_SENDER_ERROR")});n(e)}else{if(BX.type.isFunction(t)){t()}a(e)}},onfailure:function(e){BX.UI.Notification.Center.notify({content:BX.message("MAIN_MAIL_DELETE_SENDER_ERROR")});n(e)}})}))},onCancel:function(e){e.close()}})}};window.BXMainMailConfirm=n})();
//# sourceMappingURL=script.map.js